define("zui/tab",function(require,exports,module){

	  function zTab(options){
	  	if(options&&options.srcNode){
	  		this.el=options.srcNode;
	  		this.tabs(options);

	  	}

	  }

	
	  zTab.prototype={

	  		tabs:function(options){
	  			var _self=this,options=$.extend({},options||{});
	  			if(options.history==true){
	  					options.activate=function(e, to){
				            var index = to.index+1;
				            if(flag)return ;
				            setTimeout(function(){//马上就改变hash的话在android里面会影响动画执行。原因不明
				                if (typeof(window.history.pushState) == 'function') {
				                    history.pushState(null, 'tab '+index, '#tabs'+index);
				                } else {
				                    window.location.hash = '#tabs'+index;
				                }
				            }, $.os.android?400:0);
				        };
				        //历史记录
				        _self._historyHashChange();
	  			}
	  			 if(options.ajaxType==true){
	  			 		_self._ajaxTabs(options);
	  			 		return;
	  			 }
	  			 $(options.srcNode).tabs(options);
	  		},
	  		switchTo:function(index){
	  			 var _self=this;
	  			 $(_self.el).tabs("switchTo",index);
	  		},
	  		refreshTab:function(){
	  			 var _self=this;
	  			 $(_self.el).tabs("refresh");
	  		},
	  		destroy:function(){
	  			 var _self=this;
	  			 $(_self.el).tabs("destroy");
	  		},
	  		_ajaxTabs:function(options){
	  			var _self=this;
	  			var options=$.extend({
	  				ajax: {
			            type: 'POST',
			            contentType: 'application/x-www-form-urlencoded'
			        },
			        beforeLoad: function(e, xhr, settings){
			            var ui = this;
			            settings.data = $.param({
			                index: ui._options['active']
			            });
			       }
			   },options||{});

	  		   $(options.srcNode).tabs(options);
	  		},
	  		_historyHashChange:function(){
	  			var _self=this;
		        $(window).on('hashchange popstate', function(event){
			        var index = /^#tabs(\d+)$/.test(location.hash) && parseInt(RegExp.$1)-1 || 0;
			        setTimeout(function(){//android下hash一变不能马上开始动画，否则会有影响！原因不明
			            flag = true;//标记一下，手动切换过去不用载入history纪录
			            _self.switchTo(index);
			            flag = false;
			        }, $.os.android?400:0);
			    });
	  		}


	  }

	  return zTab;

})